package com.zoshine.zzg.controller;

import com.github.pagehelper.PageInfo;
import com.zoshine.zzg.annotation.DisableLoginCheck;
import com.zoshine.zzg.base.BaseResponse;
import com.zoshine.zzg.pojo.GoodsPublishDetail;
import com.zoshine.zzg.pojo.User;
import com.zoshine.zzg.pojo.pojostatus.GoodsPublicStatus;
import com.zoshine.zzg.respons.AppResponse;
import com.zoshine.zzg.service.GoodsPublishDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 田沛凌
 * @time 2017/7/18 11:21
 */
@RestController
@RequestMapping(value = "/goodsPublish",method = RequestMethod.POST)
public class GoodsPublishController extends BaseController{
//    private GoodsPublishService goodsPublishService;
    private GoodsPublishDetailService goodsPublishDetailService;
//    @Autowired
//    public void setGoodsPublishService(GoodsPublishService goodsPublishService) {
//        this.goodsPublishService = goodsPublishService;
//    }
    @Autowired
    public void setGoodsPublishDetailService(GoodsPublishDetailService goodsPublishDetailService) {
        this.goodsPublishDetailService = goodsPublishDetailService;
    }

    /**
     * 新增上架商品
     */
    @RequestMapping("/addGoodsPublish")
    public BaseResponse addGoodsPublish(GoodsPublishDetail goodsPublishDetail) {
        User loginUser = super.getLoginUser();
        goodsPublishDetail.setUserId(loginUser.getId());
        goodsPublishDetailService.add(goodsPublishDetail);
        return AppResponse.OK;
    }

    /**
     * 上架申请
     */
    @RequestMapping("/upAudit")
    public BaseResponse upAudit(String idStr) {
        goodsPublishDetailService.upAudit(idStr);
        return AppResponse.OK;
    }

    /**
     * 商品上架审核通过
     */
    @RequestMapping("/upAuditPass")
    public BaseResponse passGoodsPublish(String idStr){
        goodsPublishDetailService.upAuditPass(idStr);
        return AppResponse.OK;
    }

    /**
     * 商品上架审核不通过
     */
    @RequestMapping("/upAuditFail")
    public BaseResponse upAuditFail(String idStr) {
        goodsPublishDetailService.upAuditFail(idStr);
        return AppResponse.OK;
    }

    /**
     * 申请下架
     */
    @RequestMapping("/downAudit")
    public BaseResponse downAudit(String idStr) {
        goodsPublishDetailService.downAudit(idStr);
        return AppResponse.OK;
    }

    /**
     * 下架通过
     */
    @RequestMapping("/downAuditPass")
    public BaseResponse downAuditPass(String idStr) {
        goodsPublishDetailService.downAuditPass(idStr);
        return AppResponse.OK;
    }

    /**
     * 下架不通过
     */
    @RequestMapping("/downAuditFail")
    public BaseResponse downAuditFail(String idStr) {
        goodsPublishDetailService.downAuditFail(idStr);
        return AppResponse.OK;
    }

    /**
     * 下架商品
     */
    @RequestMapping("/down")
    public BaseResponse down(String idStr) {
        goodsPublishDetailService.down(idStr);
        return AppResponse.OK;
    }

    /**
     * 驳回处理
     */
    @RequestMapping("/failConfirm")
    public BaseResponse failConfirm(String idStr) {
        goodsPublishDetailService.failConfirm(idStr);
        return AppResponse.OK;
    }

    /**
     * 下架商品
     */
    @RequestMapping("/batchDel")
    public BaseResponse batchDel(String idStr) {
        goodsPublishDetailService.batchDel(idStr);
        return AppResponse.OK;
    }
//    /**
//     * 上架商品记录查询(分页)
//     * @param goodsPublic (对象)
//     * @return 上架商品集合
//     */
//    @DisableLoginCheck
//    @RequestMapping("/pageGoodsPublish")
//    public BaseResponse pageGoodsPublish(GoodsPublish goodsPublic){
//        List<Long> supplierPower =super.getSupplierPower();
//        List<Long> prisonPower = super.getPrisonPower();
//        goodsPublic.setSupplierPower(supplierPower);
//        goodsPublic.setPrisonPower(prisonPower);
//        List<GoodsPublish> list = goodsPublishService.list(goodsPublic);
//        return new AppResponse(new PageInfo<>(list));
//    }

//    /**
//     * 查询商品上架详情
//     * @param id (上架ID)
//     * @return 上架详情集合
//     */
//    @DisableLoginCheck
//    @RequestMapping("/listPublishDetail")
//    public BaseResponse listPublishDetail(Long id){
//        GoodsPublishDetail goodsPublishDetail=new GoodsPublishDetail();
//        goodsPublishDetail.setPublishId(id);
//        goodsPublishDetail.setGoodsStatus(GoodsPublicStatus.PUBLISH.getValue());
//        List<GoodsPublishDetail> goodsPublishDetails = goodsPublishDetailService.list(goodsPublishDetail);
//        return new AppResponse(goodsPublishDetails);
//    }
    /**
     * 查询上架商品
     * @param goodsPublishDetail ;
     * @return 上架详情集合
     */
    @DisableLoginCheck
    @RequestMapping("/pagePublishDetail")
    public BaseResponse pagePublishDetail(GoodsPublishDetail goodsPublishDetail){
        List<Long> supplierPower =super.getSupplierPower();
        List<Long> prisonPower = super.getPrisonPower();
        goodsPublishDetail.setSupplierPower(supplierPower);
        goodsPublishDetail.setPrisonPower(prisonPower);
        List<GoodsPublishDetail> goodsPublishDetails = goodsPublishDetailService.list(goodsPublishDetail);
        return new AppResponse(new PageInfo<>(goodsPublishDetails));
    }
//    /**
//     * 申请商品下架
//     */
//    @RequestMapping("/downGoodsPublish")
//    public BaseResponse downGoodsPublish(String delIdStr) {
//        goodsPublishService.downGoodsPublish(delIdStr);
//        return AppResponse.OK;
//    }

//    /**
//     * 通过申请下架
//     */
//    @RequestMapping("/passDownGoodsPublish")
//    public BaseResponse passDownGoodsPublish(String delIdStr) {
//        goodsPublishService.passDownGoodsPublish(delIdStr);
//        return AppResponse.OK;
//    }

//    /**
//     * 不通过申请下架
//     */
//    @RequestMapping("/failDownGoodsPublish")
//    public BaseResponse failDownGoodsPublish(String delIdStr) {
//        goodsPublishService.failDownGoodsPublish(delIdStr);
//        return AppResponse.OK;
//    }

    /**
     * 获取单个上架详情
     * @param id (详情ID)
     */
    @DisableLoginCheck
    @RequestMapping("/getGoodsPublishDetail")
    public BaseResponse getGoodsPublishDetail(Long id){
        GoodsPublishDetail goodsPublishDetail = goodsPublishDetailService.get(id);
        return new AppResponse(goodsPublishDetail);
    }
    /**
     * 删除商品上架详情
     * @param id (上架详情ID)
     */
    @RequestMapping("/delGoodsPublishDetail")
    public BaseResponse delGoodsPublishDetail(Long id){
//        GoodsPublishDetail goodsPublishDetail = goodsPublishDetailService.get(id);
//        if (!(goodsPublishDetail.getGoodsStatus().equals(GoodsPublicStatus.AUDITING.getValue()))){
//            throw new AppException(ErrorMessage.GOODS_STATUS_CAN_NOT_BACK);
//        }
        goodsPublishDetailService.del(id);
        return AppResponse.OK;
    }

    /**
     * 修改商品上架详情
     * @param goodsPublishDetail （详情对象）
     */
    @DisableLoginCheck
    @RequestMapping("/editGoodsPublishDetail")
    public BaseResponse editGoodsPublishDetail(GoodsPublishDetail goodsPublishDetail){
//        GoodsPublishDetail temp = goodsPublishDetailService.get(goodsPublishDetail.getId());
//        if (!(temp.getGoodsStatus().equals(GoodsPublicStatus.AUDITING.getValue()))){
//            throw new AppException(ErrorMessage.GOODS_STATUS_CAN_NOT_BACK);
//        }
//        goodsPublishDetail.setGoodsStatus(GoodsPublicStatus.AUDITING.getValue());
        goodsPublishDetailService.edit(goodsPublishDetail);
        return AppResponse.OK;
    }

//    /**
//     * 商品上架审核不通过
//     * @param idStr (上架商品ID集合)
//     */
//    @RequestMapping("/failGoodsPublishDetail")
//    public BaseResponse failGoodsPublish(String idStr){
//        goodsPublishService.changeGoodsPublishDetailStatus(GoodsPublicStatus.DOWN_AUDIT.getValue(),idStr);
//        return AppResponse.OK;
//    }


    /**
     * 获取商品状态列表
     */
    @RequestMapping("/listGoodsPublicStatus")
    public BaseResponse listGoodsPublicStatus() {
        return new AppResponse(GoodsPublicStatus.getList());
    }

}
